package cl.rizepe.playntest.core.effects;

import static playn.core.PlayN.graphics;
import playn.core.Canvas;
import playn.core.CanvasImage;
import playn.core.Color;
import pythagoras.f.Point;
import cl.rizepe.playntest.core.views.EffectedLayer;

public class Shape extends EffectLayerBlank {	
	int color;
	float alpha;
	
	public Shape (EffectedLayer layerState){
		this(layerState, 0.5f);
	}
	
	public Shape (EffectedLayer layerState, float alpha){
		this(layerState, Color.rgb(255, 0, 0),alpha);
	}
	
	public Shape (EffectedLayer layerState, int color, float alpha){
		super(layerState);
		this.color=color;
		this.alpha=alpha;
	//	drawShape();
		shape=graphics().createImageLayer(graphics().createImage(1,1));
		shape.setVisible(false);
	}
	
	protected void drawShape() {
		if (shape!=null)
			shape.destroy();
		float diameter =layerState.getCircumscribedDiameter();
		CanvasImage canvasImage =graphics().createImage(diameter*2,diameter*2);
		shape=graphics().createImageLayer(canvasImage);
		//pythagoras.f.Transform t = layerState.getImageLayer().transform();
		shape.setOrigin(0,0);
		//shape.setTranslation(t.tx()-layer.width()/2, t.ty()-layer.height()/2);
		Point translation = layerState.getTranslate();
		shape.setTranslation(translation.x()-diameter/2, translation.y()-diameter/2);
		Canvas canvas;
		canvas=canvasImage.canvas();
		canvas.clear();
		canvas.setFillColor(color);
		//canvas.setFillColor(Color.rgb(255, 0, 0));
		canvas.setAlpha(alpha);
		canvas.fillCircle(diameter/2, diameter/2, diameter/2);
		if (layerState.parent()!=null)
			layerState.parent().add(shape);
	}


}
